package com.yq.tanhua.im;

import com.hyphenate.chat.EMConversation;

/**
 * @author: user
 * @date: 2023/5/11
 */
public class ImUtils {
    /**
     * change the chat type to EMConversationType
     *
     * @param chatType
     * @return
     */
    public static EMConversation.EMConversationType getConversationType(int chatType) {
        if (chatType == ImConstant.CHATTYPE_SINGLE) {
            return EMConversation.EMConversationType.Chat;
        } else if (chatType == ImConstant.CHATTYPE_GROUP) {
            return EMConversation.EMConversationType.GroupChat;
        } else {
            return EMConversation.EMConversationType.ChatRoom;
        }
    }

    /**
     * get chat type by conversation type
     *
     * @param conversation
     * @return
     */
    public static int getChatType(EMConversation conversation) {
        if (conversation.isGroup()) {
            if (conversation.getType() == EMConversation.EMConversationType.ChatRoom) {
                return ImConstant.CHATTYPE_CHATROOM;
            } else {
                return ImConstant.CHATTYPE_GROUP;
            }
        } else {
            return ImConstant.CHATTYPE_SINGLE;
        }
    }
}
